﻿USE CLR_TEST;
/*
 * File operations
 */

SELECT * FROM DbExt.Dir('c:\', '*') WHERE IsReadOnly = 0

SELECT DbExt.FileCopy('D:\TestFolder\A\Test.txt', 'D:\TestFolder\B\Test.txt', 1)
SELECT DbExt.FileExists('D:\TestFolder\A\Test.txt')
SELECT DbExt.FileRename('D:\TestFolder\B\Test.txt', 'D:\TestFolder\B\Text.txt')
SELECT DbExt.FileMove('D:\TestFolder\B\Text.txt', 'D:\TestFolder\A\Text.txt')
SELECT DbExt.FileDelete('D:\TestFolder\A\Text.txt')

SELECT * FROM DbExt.FileReadAllLines('e:\20080725.gpx')
WHERE LineNumber BETWEEN 10 AND 20
;
SELECT DbExt.FileReadAllText('e:\20080725.gpx');

DECLARE @Contents NVARCHAR(MAX) = 'Line 1' + CHAR(13) + 'Line 2' + CHAR(13) + 'Line 3' 
SELECT DbExt.FileWriteAllText('D:\TestFolder\dummy.txt', @Contents)


--SELECT DbExt.ShareConnect('J', '\\computer\sharename', 'username', 'secret')

--SELECT DbExt.FileCopy('D:\TestFolder\A\Test.txt', 'J:\Test.txt', 1)
-- Look for this file, it is really there
--SELECT DbExt.FileDelete('J:\Test.txt')
--SELECT DbExt.ShareDisconnect('J')

/*
 * Examples for string operations
 */
DECLARE @VALUE NVARCHAR(255) = '125'
SELECT DbExt.LPad(@VALUE, 6, '+')
SELECT DbExt.RPad(@VALUE, 6, '+')


DECLARE @CSV_TEST TABLE ( TEXT_FIELD NVARCHAR(50) )
DECLARE @Result NVARCHAR(MAX)

INSERT INTO @CSV_TEST ( TEXT_FIELD ) VALUES ('1'), ('a'), ('r'), ('0')

SELECT @Result = DbExt.CSV(TEXT_FIELD, ',') FROM @CSV_TEST;
SELECT @Result
SELECT * FROM DbExt.Split(@Result, ',')

SELECT DbExt.SubStr('Munich lost champions league final', 8);

SELECT DbExt.Remove('Munich lost champions league final', 8, 5);
SELECT DbExt.Remove('Munich lost champions league final', 8, NULL);

SELECT DbExt.TrimStart('++123++', '+')
SELECT DbExt.TrimEnd('++123++', '+')

IF DbExt.StartsWith('Munich lost champions league final', 'Mun') = 1
	SELECT '"Mun" was found'
	
IF DbExt.EndsWith('Munich lost champions league final', 'inal') = 1
	SELECT '"inal" was found'

IF DbExt.[Contains]('Munich lost champions league final', 'league') = 1
	SELECT '"league" was found'

 SELECT DbExt.[RailCheckDigit]('19052') CheckDigit
 SELECT DbExt.[RailCheckDigit]('11231') CheckDigit